package com.hmdp.config;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @package: com.hmdp.config
 * @className: RabbitMQConfig
 * @author: 云溪
 * @description:
 * @date: 2025/9/16 13:43
 * @version: 1.0
 */
@RequiredArgsConstructor
@Configuration
public class RabbitMQConfig {


    /**
     * -  RejectAndDontRequeueRecoverer：重试耗尽后，直接reject，丢弃消息。默认就是这种方式
     * -  ImmediateRequeueMessageRecoverer：重试耗尽后，返回nack，消息重新入队
     * -  RepublishMessageRecoverer：重试耗尽后，将失败消息投递到指定的交换机
     * @param
     * @return
     */
    // 替代原来的失败处理策略
    @Bean
    public MessageRecoverer messageRecoverer (RabbitTemplate rabbitTemplate){
        return new RepublishMessageRecoverer(rabbitTemplate,"error.direct","error");
    }


}
